package com.h2cloud.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.text.SimpleDateFormat;
import java.util.Date;

//配置 图片 url与 本地文件路径映射
@Configuration
public class FileUploadConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        System.out.println("配置文件映射");

        //获取文件的真实路径
        String path = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\upload\\";
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + path);

        String path2 = System.getProperty("user.dir") + "\\src\\main\\resources\\templates\\css\\";
        registry.addResourceHandler("/css/**").addResourceLocations("file:" + path2);

        String path3 = System.getProperty("user.dir") + "\\src\\main\\resources\\templates\\js\\";
        registry.addResourceHandler("/js/**").addResourceLocations("file:" + path3);

        String path4 = System.getProperty("user.dir") + "\\src\\main\\resources\\templates\\img\\";
        registry.addResourceHandler("/img/**").addResourceLocations("file:" + path4);
    }
}
